<?php
/*
+--------------------------------------------------------------------------
|   phpBIZbiz v3.0 full version
|   ========================================
|   by taft@wjl.cn
|   http://www.phpbiz.cn
|   all rights reserved
+---------------------------------------------------------------------------
|
|   > 
|   > 最后修改日期：2005-9-9
|   > 
|
+--------------------------------------------------------------------------
*/
!function_exists('do_login') && exit('Forbidden');
$cat = new ad_cat();

class ad_cat {

	var $base_url;

	function ad_cat() 
	{
		global $INCOME,$CONF;

		$this -> base_url = $CONF['admin_url']."admin.".$CONF['php_ext'];
		
		//---------------------------------------
		// Kill globals - globals bad, Homer good.
		//---------------------------------------
		
		$tmp_in = array_merge( $_GET, $_POST, $_COOKIE );
		
		foreach ( $tmp_in as $k => $v )
		{
			unset($$k);
		}

		//---------------------------------------

		switch($INCOME['code'])
		{
			case 'new':
				$this -> new_form();
			    break;
			case 'snew':
				$this -> shop_new_form();
			    break;
			case 'donew':
				$this -> do_new();
			    break;
			case 'dosnew':
				$this -> do_shop_new();
			    break;
			case 'seditform':
				$this -> do_shop_edit();   //form and do
			    break;
			case 'edit':
				$this -> edit_form();
			    break;
			case 'sedit':
				$this -> shop_edit_form();   //商铺的类别
			    break;
			case 'editform' :
				$this -> do_edit_form(); //编辑每个细类
			    break;
			case 'doedit' :
				$this -> do_edit();
			    break;
			case 'clearform':
				$this -> clear_form();
			    break;
			case 'doclear':
				$this -> do_clear();
			    break;
            case 'moveform':
				$this -> move_form();
			    break;
			case 'smoveform':
			    $this -> shop_move_form();
				break;
			case 'domove':
				$this -> do_move();
			    break;
			case 'sclearform':
				$this -> shop_clear_form();
			    break;
			default :
		}
	}

	function new_form()
	{
		global $ADMIN,$SKIN,$DB;

		$cat_name = "";
		
		$ADMIN->page_title = "新建商品类别";
		
		$ADMIN->page_instruction = "这个区域允许你给phpBIZ添加一个新的商品类别。如果添加为顶级类别，选择‘--单独父类--’。如果添加子类，则选择相应的子类为新添加的父类即可。";


		//-------------------------------------------------------------
		// retrive the parent catalog
		//-------------------------------------------------------------
		$DB -> db_query( " SELECT * FROM biz_goods_cat WHERE goods_cat_parent_id =0" );

		
		$form_array[] = array(0,"--单独父类--");

		while ( $r = $DB->db_fetch_row() )
		{
			$form_array[] = array( $r['goods_cat_id'] , $r['goods_cat_name'] );
		}
		//--------------------------------------------------------------
        
		$ADMIN->html .= $SKIN->form_head();
		$SKIN->td_header[] = array( "&nbsp;"  , "30%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );

		$ADMIN->html .= $SKIN->table_head( "必须的" );

		
		$ADMIN->html .= $SKIN->form_input( "act","cat","hidden");
		$ADMIN->html .= $SKIN->form_input( "code","donew","hidden");

		$ADMIN->html .= $SKIN->table_row( array( "<b>商品类别名称</b>" ,
												  $SKIN->form_input("CAT_NAME", $cat_name)
									     )      );
		$ADMIN->html .= $SKIN->table_row( array("<b>商品的父类</b>",$SKIN->form_droplist("parent_id",$form_array) ) );
		$ADMIN->html .= $SKIN->table_row( array( "<b>商品类别描述</b>",
			                                     "<TEXTAREA NAME='CAT_DESC'  ROWS='8' COLS='50'></TEXTAREA>"
		                                 )      );
    	
		$ADMIN->html .= $SKIN->form_end("创建这个类别");
										 
		$ADMIN->html .= $SKIN->table_end();
		
		$ADMIN->output();
	}

	function do_new()
	{
		global $DB,$SKIN,$ADMIN,$INCOME;

	    if( $INCOME['CAT_NAME'] =="") 
			$ADMIN -> error("请输入商品类别名！");

	    $pid = intval($INCOME['parent_id']);
        
		$db_string = $DB -> db_compile_fields(  array(  
			                                             "goods_cat_name" => $INCOME['CAT_NAME'],
			                                              "goods_cat_describle" => $INCOME['CAT_DESC'],
		                                                  "goods_cat_parent_id" => $pid					          
		));
		$DB->db_query("INSERT INTO biz_goods_cat (".$db_string['fields'].") VALUES (".$db_string['value'].")");
        $ADMIN -> recache();
		$ADMIN->record_log("添加商品类别‘<b>{$INCOME['CAT_NAME']}</b>’");
		$ADMIN->done_screen("商品类别 {$INCOME['CAT_NAME']} 已创建", "类别控制", "act=cat&code=edit" );

	}

	function edit_form()
	{
		global $SKIN,$ADMIN,$DB;

        $DB -> db_query( "SELECT a.goods_cat_name as aname,a.goods_cat_id as aid,b.goods_cat_name as bname,b.goods_cat_id as bid FROM biz_goods_cat a LEFT JOIN biz_goods_cat b ON b.goods_cat_parent_id =a.goods_cat_id WHERE a.goods_cat_parent_id = 0" );
		
		$ADMIN->page_title = "管理商品类别";
		
		$ADMIN->page_instruction = "这个区域允许你编辑商品类别。<br>'移除'指移动该选定下的所有商品到其他类别后删除该类别。<br>'清除'指删除该类别的所有商品和该类别。";

		$SKIN -> td_header[] = array("父 类","15%");
		$SKIN -> td_header[] = array(" ","20%");
		$SKIN -> td_header[] = array("子 类","15%");
		$SKIN -> td_header[] = array(" ","20%");

		$num = $DB -> db_fetch_num();

		if( $num < 1 ) 
			$ADMIN -> error("目前没有建立任何商品类别，<a href='{$this->base_url}?act=cat&code=new'><b>点击这里新建</b></a>");

		while( $cat = $DB -> db_fetch_row() )
		{
			 $cat_array[]=array($cat['aname'],$cat['aid'],$cat['bname'],$cat['bid']);
		}
		
		$num = count($cat_array);

		$ADMIN -> html .= $SKIN -> table_head( "$num 个商品类别");
		
		for($i=0; $i<$num; $i++)
		{
			
			if($cat_array[$i][1]!=$cat_array[$i-1][1]) 
			{     
				$str = $cat_array[$i][2]? "<center><a href='{$this->base_url}?act=cat&code=editform&id={$cat_array[$i][3]}'>编辑</a> <a href='{$this->base_url}?act=cat&code=moveform&id={$cat_array[$i][3]}'>移除</a> <a href='{$this->base_url}?act=cat&code=clearform&id={$cat_array[$i][3]}'>清除</a></center> ":"";
				$ADMIN -> html .= $SKIN -> table_row(
					                                  array(
				                                       "<img src='{$SKIN -> img_url}/item.gif' border='0' alt='-'>&nbsp;".$cat_array[$i][0],"<center><a href='{$this->base_url}?act=cat&code=editform&id={$cat_array[$i][1]}'>编辑</a> <a href='{$this->base_url}?act=cat&code=moveform&id={$cat_array[$i][1]}'>移除</a> <a href='{$this->base_url}?act=cat&code=clearform&id={$cat_array[$i][1]}'>清除</a></center> "," " ," "											  
													   )
												);
			    $ADMIN -> html .= $SKIN -> table_row(
					                                  array(
				                                       " "," ",$cat_array[$i][2],$str												  
													   )
												);
 			}
			else
				$ADMIN -> html .= $SKIN -> table_row(
					                                  array(
				                                       " "," ",$cat_array[$i][2],
													   "<center><a href='{$this->base_url}?act=cat&code=editform&id={$cat_array[$i][3]}'>编辑</a> <a href='{$this->base_url}?act=cat&code=moveform&id={$cat_array[$i][3]}'>移除</a> <a href='{$this->base_url}?act=cat&code=clearform&id={$cat_array[$i][3]}'>清除</a></center>")
												);


		}

		$ADMIN -> html .= $SKIN -> table_end();

		$ADMIN -> output();
	}

	function do_edit_form()
	{
		global $ADMIN,$DB,$INCOME,$SKIN;

		$id = intval( $INCOME['id'] );

		$DB -> db_query( " SELECT * FROM biz_goods_cat WHERE goods_cat_id = '$id' LIMIT 0,1" );
        $cat = $DB -> db_fetch_row();
	    
		if( $DB -> db_fetch_num() < 1 ) $ADMIN -> error( "你的搜索查询没有从数据库中返回任何匹配。请返回并重试" );

		$ADMIN -> page_title = "编辑类别细节";

		$SKIN -> td_header[] = array("&nbsp;","30%");
		$SKIN -> td_header[] = array("&nbsp;","70%");
        
		$ADMIN -> html .= $SKIN -> table_head("&nbsp;");
        
		$ADMIN -> html .= $SKIN -> form_head();
		$ADMIN -> html .= $SKIN -> form_input("act","cat","hidden");
		$ADMIN -> html .= $SKIN -> form_input("code","doedit","hidden");
		$ADMIN -> html .= $SKIN -> form_input("id","{$cat[goods_cat_id]}","hidden");


		$ADMIN -> html .= $SKIN -> table_row (  array( "商品类名", 
			                                           $SKIN -> form_input("goods_cat_name",$cat[goods_cat_name])
			                                 ) );

		$ADMIN -> html .= $SKIN -> table_row ( array( "商品类描述", "<TEXTAREA NAME='goods_cat_describle' ROWS='8' COLS='50'>$cat[goods_cat_describle]</TEXTAREA>"));

		$ADMIN -> html .= $SKIN -> form_end("提交修改");

		$ADMIN -> html .= $SKIN -> table_end();

		$ADMIN -> output();

	
	}

	function do_edit()
	{
		global $ADMIN,$SKIN,$INCOME,$DB;

		$id = intval( $INCOME['id'] );

		$DB -> db_query( " SELECT * FROM biz_goods_cat WHERE goods_cat_id = '$id' LIMIT 0,1" );
	    
		if( $DB -> db_fetch_num() < 1 ) $ADMIN -> error( "你的搜索查询没有从数据库中返回任何匹配。请返回并重试" );

        $db_string = $DB-> db_compile_update_fields ( array( "goods_cat_name" => $INCOME[goods_cat_name],
			                                                  "goods_cat_describle" => $INCOME[goods_cat_describle] ));
		$db_query = "UPDATE biz_goods_cat SET $db_string WHERE  goods_cat_id ='".$id."'";
		$DB -> db_query( $db_query );

		$ADMIN->record_log("修改商品类别为‘$INCOME[goods_cat_name]’");
        $ADMIN->done_screen("商品类别已修改", "类别控制", "act=cat&code=edit" );
	}

	function move_form()
	{
		global $ADMIN,$SKIN,$INCOME,$DB;

		$id = intval( $INCOME['id'] );

		$DB -> db_query( " SELECT * FROM biz_goods_cat " );
         
		$num = $DB -> db_fetch_num();
		
		if( $num < 1 ) $ADMIN -> error( "你的操作查询没有从数据库中返回任何匹配。请返回并重试" );
	
		if( $num ==1 ) $ADMIN -> error( "由于目前只有一个类别，请<a href='{$this->base_url}?act=cat&code=new'><b>再建一个类别</b></a>后选择移出");
		
		while ( $r = $DB->db_fetch_row() )
		{
			if( $r['goods_cat_id'] != $id ) $form_array[] = array( $r['goods_cat_id'] , $r['goods_cat_name'] );
		}
		
		$ADMIN -> page_title ="移除类别";
		
		$SKIN -> td_header[] = array("&nbsp;","40%");
		$SKIN -> td_header[] = array("&nbsp;","60%");

	    $ADMIN -> html .= $SKIN -> table_head("移除类别","请小心操作！");

		$ADMIN -> html .= $SKIN -> form_head();
		$ADMIN -> html .= $SKIN -> form_input("act","cat","hidden");
		$ADMIN -> html .= $SKIN -> form_input("code","domove","hidden");
		$ADMIN -> html .= $SKIN -> form_input("clear_id",$id,"hidden");

		$ADMIN -> html .= $SKIN -> table_row( array( "移除类别,并且把此类下的商品移动到：",$SKIN->form_droplist( "to_id", $form_array)
			));
        $ADMIN -> html .= $SKIN -> form_end("移除类别");
		$ADMIN -> html .= $SKIN -> table_end();

		$ADMIN -> output();
	}

	function do_move()
	{
		global $ADMIN,$DB,$INCOME,$SKIN;

		$id    = intval( $INCOME['clear_id'] );
		$to_id = intval( $INCOME['to_id'] );

		$DB -> db_query( " SELECT goods_cat_name as n FROM biz_goods_cat WHERE goods_cat_id = '$id' LIMIT 0,1" );
        $cat = $DB -> db_fetch_row(); 
		
		if( $DB -> db_fetch_num() < 1 ) $ADMIN -> error( "你的操作没有从数据库中返回任何匹配。请返回并重试" );
        
		$DB -> db_query("UPDATE biz_goods SET goods_cat_id ='$to_id' WHERE goods_cat_id='$id'");

		$DB -> db_query( " DELETE FROM biz_goods_cat WHERE goods_cat_id ='$id' LIMIT 1 " );
        $ADMIN -> record_log("移除商品类‘<b>$cat[n]</b>’");
		$ADMIN -> done_screen("商品类别已移除", "类别控制", "act=cat&code=edit" );

	}

	function clear_form()
	{
		global $ADMIN,$SKIN,$DB,$INCOME;

		$id = intval( $INCOME['id'] );

		$DB -> db_query( " SELECT * FROM biz_goods_cat WHERE goods_cat_id = '$id' LIMIT 1" );
         
		if( $DB -> db_fetch_num() < 1 ) $ADMIN -> error( "你的操作查询没有从数据库中返回任何匹配。请返回并重试" );
	
		$cat = $DB -> db_fetch_row();

		$ADMIN -> page_title ="清除类别";
		$ADMIN -> page_instructon = "被清除类别下的所有商品及相关信息也将被删除，请小心操作！";
        
		/*--------------del pic ----------------*/
	    $rs = $DB -> db_query( "SELECT goods_id as g FROM biz_goods WHERE goods_cat_id ='$id' " );
        while ( $ar = $DB ->db_fetch_row( $rs ) )
		{
			$DB -> db_query( "DELETE FROM biz_pic  WHERE pic_goods_id = '$ar[g]' LIMIT 1" );
			$DB -> db_query( "DELETE FROM biz_message WHERE message_owner_goods_id = '$ar[g]' LIMIT 1" );
			$DB -> db_query( "DELETE FROM biz_goods WHERE goods_id ='$ar[g]' LIMIT 1" );
		}



		$DB -> db_query( "DELETE FROM biz_goods_cat WHERE goods_cat_id = '$id' LIMIT 1" );
        $DB->db_query("UPDATE biz_goods_cat SET goods_cat_name = goods_cat_name - 1,goods_cat_describle=goods_cat_describle-1 WHERE goods_cat_id=0");
		$ADMIN -> recache();
		$ADMIN -> record_log( "清除商品类‘<b>$cat[n]</b>’" );
		$ADMIN -> done_screen( "商品类别已清除", "类别控制", "act=cat&code=edit" ) ;

	}

	function shop_new_form()
	{
		global $ADMIN,$SKIN,$DB;

		$cat_name = "";
		
		$ADMIN->page_title = "新建商铺类别";
		
		$ADMIN->page_instruction = "这个区域允许你给phpBIZ添加一个新的商铺类别。如果添加为顶级类别，选择‘--单独父类--’。如果添加子类，则选择相应的子类为新添加的父类即可。";


		//-------------------------------------------------------------
		// retrive the parent catalog
		//-------------------------------------------------------------
		$DB -> db_query( " SELECT * FROM biz_shop_cat WHERE shop_cat_parent_id =0" );

		
		$form_array[] = array(0,"--单独父类--");

		while ( $r = $DB->db_fetch_row() )
		{
			$form_array[] = array( $r['shop_cat_id'] , $r['shop_cat_name'] );
		}
		//--------------------------------------------------------------
        
		$ADMIN->html .= $SKIN->form_head();
		$SKIN->td_header[] = array( "&nbsp;"  , "30%" );
		$SKIN->td_header[] = array( "&nbsp;"  , "60%" );

		$ADMIN->html .= $SKIN->table_head( "必须的" );

		
		$ADMIN->html .= $SKIN->form_input( "act","cat","hidden");
		$ADMIN->html .= $SKIN->form_input( "code","dosnew","hidden");

		$ADMIN->html .= $SKIN->table_row( array( "<b>商铺类别名称</b>" ,
												  $SKIN->form_input("CAT_NAME", $cat_name)
									     )      );
		$ADMIN->html .= $SKIN->table_row( array("<b>商铺的父类</b>",$SKIN->form_droplist("parent_id",$form_array) ) );
		$ADMIN -> html .= $SKIN -> table_row(array("<b>是否加入导航菜单</b>","<input type='checkbox' name='nav' value=1 $sign> 请确保只能同时设定显示两个商品类别名"));
		$ADMIN->html .= $SKIN->table_row( array( "<b>商铺类别描述</b>",
			                                     "<TEXTAREA NAME='CAT_DESC'  ROWS='8' COLS='50'></TEXTAREA>"
		                                 )      );
    	
		$ADMIN->html .= $SKIN->form_end("创建这个类别");
										 
		$ADMIN->html .= $SKIN->table_end();
		
		$ADMIN->output();
	}

	function do_shop_new()
	{
		global $DB,$SKIN,$ADMIN,$INCOME;

	    if( $INCOME['CAT_NAME'] =="") 
			$ADMIN -> error("请输入商铺类别名！");

	    $pid = intval($INCOME['parent_id']);
        
		$db_string = $DB -> db_compile_fields(  array(  
			                                             "shop_cat_name" => $INCOME['CAT_NAME'],
			                                              "shop_cat_describe" => $INCOME['CAT_DESC'],
		                                                  "shop_cat_parent_id" => $pid,
			                                              "nav" => $INCOME[nav],
		));
		$DB->db_query("INSERT INTO biz_shop_cat (".$db_string['fields'].") VALUES (".$db_string['value'].")");
		$ADMIN -> recache();
		$ADMIN->record_log("添加商铺类别‘<b>{$INCOME['CAT_NAME']}</b>’");
		$ADMIN->done_screen("商铺类别 {$INCOME['CAT_NAME']} 已创建", "类别控制", "act=cat&code=sedit" );

	}

	function shop_edit_form()
	{
		global $SKIN,$ADMIN,$DB;

        $DB -> db_query( "SELECT a.shop_cat_name as aname,a.shop_cat_id as aid,b.shop_cat_name as bname,b.shop_cat_id as bid FROM biz_shop_cat a LEFT JOIN biz_shop_cat b ON b.shop_cat_parent_id =a.shop_cat_id WHERE a.shop_cat_parent_id = 0" );
		
		$ADMIN->page_title = "管理商铺类别";
		
		$ADMIN->page_instruction = "这个区域允许你编辑商铺类别。";

		$SKIN -> td_header[] = array("父 类","15%");
		$SKIN -> td_header[] = array(" ","20%");
		$SKIN -> td_header[] = array("子 类","15%");
		$SKIN -> td_header[] = array(" ","20%");

		$num = $DB -> db_fetch_num();

		if( $num < 1 ) 
			$ADMIN -> error("目前没有建立任何商铺类别，<a href='{$this->base_url}?act=cat&code=new'><b>点击这里新建</b></a>");

		while( $cat = $DB -> db_fetch_row() )
		{
			 $cat_array[]=array($cat['aname'],$cat['aid'],$cat['bname'],$cat['bid']);
		}
		
		$num = count($cat_array);

		$ADMIN -> html .= $SKIN -> table_head( "$num 个商铺类别");
		
		for($i=0; $i<$num; $i++)
		{
			
			if($cat_array[$i][1]!=$cat_array[$i-1][1]) 
			{     
				$str = $cat_array[$i][2]? "<center><a href='{$this->base_url}?act=cat&code=seditform&id={$cat_array[$i][3]}'>编辑</a> <a href='{$this->base_url}?act=cat&code=smoveform&id={$cat_array[$i][3]}'>移除</a> <a href='{$this->base_url}?act=cat&code=sclearform&id={$cat_array[$i][3]}'>清除</a></center> ":"";
				$ADMIN -> html .= $SKIN -> table_row(
					                                  array(
				                                       "<img src='{$SKIN -> img_url}/item.gif' border='0' alt='-'>&nbsp;".$cat_array[$i][0],"<center><a href='{$this->base_url}?act=cat&code=seditform&id={$cat_array[$i][1]}'>编辑</a> <a href='{$this->base_url}?act=cat&code=smoveform&id={$cat_array[$i][1]}'>移除</a> <a href='{$this->base_url}?act=cat&code=sclearform&id={$cat_array[$i][1]}'>清除</a></center> "," " ," "											  
													   )
												);
			    $ADMIN -> html .= $SKIN -> table_row(
					                                  array(
				                                       " "," ",$cat_array[$i][2],$str												  
													   )
												);
 			}
			else
				$ADMIN -> html .= $SKIN -> table_row(
					                                  array(
				                                       " "," ",$cat_array[$i][2],
													   "<center><a href='{$this->base_url}?act=cat&code=seditform&id={$cat_array[$i][3]}'>编辑</a> <a href='{$this->base_url}?act=cat&code=smoveform&id={$cat_array[$i][3]}'>移除</a> <a href='{$this->base_url}?act=cat&code=sclearform&id={$cat_array[$i][3]}'>清除</a></center>")
												);


		}

		$ADMIN -> html .= $SKIN -> table_end();

		$ADMIN -> output();

	}

	function do_shop_edit()
	{
		global $ADMIN,$DB,$SKIN,$INCOME;
		$id = intval($INCOME[id]);
		if(!$INCOME[step])
		{
			//build form to edit it
			$DB -> db_query("SELECT * FROM biz_shop_cat WHERE shop_cat_id =".$id);
			if( $DB ->db_fetch_num()!=1) $ADMIN->error("商铺类别查询错误。");
			$r = $DB -> db_fetch_row();
			
			$SKIN -> td_header[] = array(" ","25%");
			$SKIN -> td_header[] = array(" ","");
			$ADMIN -> html = $SKIN ->table_head("编辑商铺类别");
			$ADMIN -> html .= $SKIN ->form_head();
			$ADMIN -> html .= $SKIN ->form_input("code","seditform","hidden");
			$ADMIN -> html .= $SKIN ->form_input("step","1","hidden");
			$ADMIN -> html .= $SKIN -> form_input("id",$id,"hidden");
					
			$ADMIN -> html .= $SKIN -> table_row(array("<b>商铺类别名称</b>",$SKIN->form_input("scname",$r[shop_cat_name]) ));
			$sign = $r[nav]?"checked":"";
			$ADMIN -> html .= $SKIN -> table_row(array("<b>是否加入前台菜单</b>","<input type='checkbox' name='nav' value=1 $sign> 请确保只能同时设定显示两个商品类别名"));
			$ADMIN -> html .= $SKIN -> table_row( array("<b>商铺类别描述</b>","<textarea name='des' rows='8' cols='50'>$r[shop_cat_describe]</textarea>") );
			$ADMIN -> html .=$SKIN -> form_end("修改");
			$ADMIN -> html .=$SKIN -> table_end();
			$ADMIN -> output();
		}elseif($INCOME[step]==1)
		{
			$db_string = 
				$DB-> db_compile_update_fields( array( 
												"shop_cat_name" => $INCOME[scname],
											"shop_cat_describe" => $INCOME[des],
				                            "nav"=>$INCOME[nav]));
			$db_query = "UPDATE biz_shop_cat SET $db_string WHERE  shop_cat_id ='".$id."'";
			$DB -> db_query( $db_query);
			$ADMIN -> recache();
			$ADMIN->record_log("修改商铺类别为‘$INCOME[goods_cat_name]’");
			$ADMIN->done_screen("商铺类别已修改", "商铺类别管理", "act=cat&code=sedit" );
		}

	}
    function shop_move_form()
	{
		global $ADMIN,$SKIN,$INCOME,$DB;

		$id = intval( $INCOME['id'] );
		
		if(!$INCOME[step])
		{
			$DB -> db_query( " SELECT * FROM biz_shop_cat " );
			$num = $DB -> db_fetch_num();
		
			if( $num < 1 ) $ADMIN -> error( "你的操作查询没有从数据库中返回任何匹配。请返回并重试" );
			if( $num ==1 ) $ADMIN -> error( "由于目前只有一个类别，请<a href='{$this->base_url}?act=cat&code=snew'><b>再建一个类别</b></a>后选择移出");
		
			while ( $r = $DB->db_fetch_row() )
			{
				if( $r['shop_cat_id'] != $id ) $form_array[] = array( $r['shop_cat_id'] , $r['shop_cat_name'] );
			}
		
			$ADMIN -> page_title ="移除类别";
		
			$SKIN -> td_header[] = array("&nbsp;","40%");
			$SKIN -> td_header[] = array("&nbsp;","60%");

			$ADMIN -> html .= $SKIN -> table_head("移除类别","请小心操作！");

			$ADMIN -> html .= $SKIN -> form_head();
			$ADMIN -> html .= $SKIN -> form_input("act","cat","hidden");
			$ADMIN -> html .= $SKIN -> form_input("code","smoveform","hidden");
			$ADMIN -> html .= $SKIN -> form_input("id",$id,"hidden");
			$ADMIN -> html .= $SKIN -> form_input("step",1,"hidden");
			$ADMIN -> html .= $SKIN -> table_row( array( "移除类别,并且把此类下的商品移动到：",$SKIN->form_droplist( "to_id", $form_array)
			));
			$ADMIN -> html .= $SKIN -> form_end("移除类别");
			$ADMIN -> html .= $SKIN -> table_end();

			$ADMIN -> output();
		}elseif($INCOME[step]==1)
		{
          	$to_id = intval($INCOME[to_id]);
			$DB -> db_query("UPDATE biz_shop SET shop_property_id ='$to_id' WHERE shop_property_id='$id'");

			$DB -> db_query( " DELETE FROM biz_shop_cat WHERE shop_cat_id ='$id' LIMIT 1 " );
			$ADMIN -> record_log("移除商铺类‘<b>$cat[n]</b>’");
			$ADMIN -> done_screen("商铺类别已移除", "类别控制", "act=cat&code=sedit" );
		  @unlink(ROOT_PATH."cache/cat_cache.php");
		}
	}
	function sedit_form()
	{
		global $ADMIN,$DB,$INCOME,$SKIN;

		$id = intval( $INCOME['id'] );
		if(!$INCOME[step])
		{
		$DB -> db_query( " SELECT * FROM biz_shop_cat WHERE shop_cat_id = '$id' LIMIT 0,1" );
        $cat = $DB -> db_fetch_row();
	    if( $DB -> db_fetch_num() < 1 ) $ADMIN -> error( "你的搜索查询没有从数据库中返回任何匹配。请返回并重试" );
		$ADMIN -> page_title = "编辑类别细节";
		$SKIN -> td_header[] = array("&nbsp;","30%");
		$SKIN -> td_header[] = array("&nbsp;","70%");
        $ADMIN -> html .= $SKIN -> table_head("&nbsp;");
        $ADMIN -> html .= $SKIN -> form_head();
		$ADMIN -> html .= $SKIN -> form_input("step","1","hidden");
		$ADMIN -> html .= $SKIN -> form_input("code","seditform","hidden");
		$ADMIN -> html .= $SKIN -> form_input("id","{$cat[shop_cat_id]}","hidden");
		$ADMIN -> html .= $SKIN -> table_row (  array( "商品类名", 
			                                           $SKIN -> form_input("shop_cat_name",$cat[shop_cat_name])
			                                 ) );
		$ADMIN -> html .= $SKIN -> table_row(array("<b>是否加入前台菜单</b>","<input type='checkbox' name='nav' value=1 $sign> 请确保只能同时设定显示两个商品类别名"));
		$ADMIN -> html .= $SKIN -> table_row ( array( "商品类描述", "<TEXTAREA NAME='shop_cat_describle' ROWS='8' COLS='50'>$cat[shop_cat_describe]</TEXTAREA>"));
		$ADMIN -> html .= $SKIN -> form_end("提交修改");
		$ADMIN -> html .= $SKIN -> table_end();
		$ADMIN -> output();
		}elseif($INCOME[step]==1)
		{
			$db_string = $DB-> db_compile_update_fields ( 
				                     array( "shop_cat_name" => $INCOME[shop_cat_name],
			                                 "shop_cat_describe" => $INCOME[shop_cat_describle] ));
		$db_query = "UPDATE biz_shop_cat SET $db_string WHERE  shop_cat_id ='".$id."'";
		$DB -> db_query( $db_query);

		$ADMIN->record_log("修改商铺类别为‘$INCOME[shop_cat_name]’");
        $ADMIN->done_screen("商铺类别已修改", "类别控制", "act=cat&code=sedit" );
		}

	}
	function shop_clear_form()
	{
		global $ADMIN,$SKIN,$DB,$INCOME,$CONF;

		$id = intval( $INCOME['id'] );
		$DB -> db_query( " SELECT * FROM biz_shop_cat WHERE shop_cat_id = '$id' LIMIT 1" );
		if( $DB -> db_fetch_num() < 1 ) $ADMIN -> error( "你的操作查询没有从数据库中返回任何匹配。请返回并重试" );
		$cat = $DB -> db_fetch_row();

		$ADMIN -> page_title ="清除类别";
		$ADMIN -> page_instructon = "被清除类别下的所有店铺及相关信息也将被删除，请小心操作！";

		$res = $DB -> db_query("SELECT shop_id FROM biz_shop WHERE shop_property_id='".$id."'");
        while( $r = $DB -> db_fetch_row($res) )
		{
			$res2 = $DB -> db_query("SELECT goods_id FROM biz_goods WHERE shop_id =".$r[shop_id]);
			while( $r2 = $DB -> db_fetch_row($res2) )
			{
				$DB -> db_query("DELETE FROM biz_message WHERE message_owner_goods_id=".$r2[goods_id]);
				$DB -> db_query("SELECT pic_name as n,pic_id as i FROM biz_pic WHERE pic_goods_id ='".$r2[goods_id]."' LIMIT 1" );
				$p = $DB -> db_fetch_row();
				if($p[i] !=1 )  { $p_cache[] = $p[n]; $p_thumb[] = $CONF[thumb_prefix].$p[n];}
				$DB -> db_query("DELETE FROM biz_pic WHERE pic_goods_id ='".$r2[goods_id]."'");
			}
			$DB -> db_query( " SELECT pic_name as n,pic_id as i FROM biz_pic WHERE pic_shop_id ='".$r[shop_id]."'" );
			$p = $DB -> db_fetch_row(); 
			if($p[i] !=1 )    {$p_cache[] = $p[n]; $p_thumb[] = $CONF[thumb_prefix].$p[n];}
			$DB -> db_query("DELETE FROM biz_pic WHERE pic_shop_id ='".$r[shop_id]."'");
			$DB -> db_query("DELETE FROM biz_goods WHERE shop_id='".$r[shop_id]."'");
		    $DB -> db_query("DELETE FROM biz_message WHERE message_owner_shop_id ='".$r[shop_id]."'");
			$DB -> db_query("DELETE FROM biz_custom_catalog  WHERE shop_id='".$r[shop_id]."'" );
		}

		$DB -> db_query("DELETE FROM biz_shop WHERE shop_property_id='".$id."'");
		$DB -> db_query("DELETE FROM biz_shop_cat WHERE shop_cat_id=".$id);
		$DB -> db_query("UPDATE biz_shop_cat SET shop_cat_parent_id=0 WHERE shop_cat_parent_id=".$id);//升级为父类
		$ADMIN -> unlink_pic( $p_cache);
        $ADMIN -> unlink_pic( $p_thumb,1);
		@unlink(ROOT_PATH."cache/cat_cache.php");
		$ADMIN->record_log("删除商铺类别");
		$ADMIN->done_screen("商铺类别及相关信息已删除", "类别控制", "act=cat&code=sedit" );

	}
}

?>